package com.woniu.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.pojo.Car;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.pojo.Patrol;
import com.woniu.vo.CarQueryVo;
import com.woniu.vo.PatrolSearchVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author dingxiong
 * @since 2022-10-12
 */
@Mapper
public interface CarMapper extends BaseMapper<Car> {

    /**
     * 修改车辆状态为禁用禁用为0，正常为1
     * @param carId 车辆id
     * @return
     */
    @Update("UPDATE t_car SET `status`=0,`update_time`=#{date} WHERE id=#{carId}")
    Boolean updateCarStatus(String carId, Date date);

    /**
     * 修改车辆状态为正常
     * @param carId
     * @return
     */
    @Update("UPDATE t_car SET `status`=1,`update_time`=#{date} WHERE id=#{carId}")
    Boolean updateCarStatusNormal(String carId,Date date);

    /**
     * 将用户与车辆进行解绑
     * @param carId 车辆id
     * @return
     */
    @Update("UPDATE t_car SET `user_id`=null,`update_time`=#{date} WHERE id=#{carId}")
    Boolean updateCarUser(String carId,Date date);

    /**
     * 将车辆与用户进行绑定
     * @param carId 车辆id
     * @param userId 用户id
     * @return
     */
    @Update("UPDATE t_car SET `user_id`=#{userId},`update_time`=#{date} WHERE id=#{carId}")
    Boolean updateCarOfUser(String carId, String userId,Date date);
    @Update("update t_car set user_id = #{userId} where id = #{carId}")
    void updateCarUserById(Long carId, Long userId);


    IPage<Car> selectPages(@Param("page") Page<Car> page, @Param("carQueryVo")CarQueryVo carQueryVo);


}
